1
The Cargo Bay: Organizing Data Collections
AI017 Lesson 5
00:00

In Go, collections are fundamentally groups of items of the same type, organized for efficient access. The "Cargo Bay" represents our need to manage bulk data under a single identifier rather than separate variables.

1. The Composite Literal

A composite literal is a concise syntax to initialize any composite type with the values you want. It allows you to declare and initialize an array in a single step using the syntax: type{value1, value2, ...}.

2. Zero-Based Navigation

Arrays are indexed starting at 0. A collection of 8 planets is accessed using indices 0 through 7. Accessing an index outside this range results in a compile-time error or a runtime panic.

Figure 16.1: Planets with Indices 0-7

[0]Mercury[1]Venus[2]Earth[3]Mars[4]Jupiter[5]Saturn[6]Uranus[7]Neptune
main.py
TERMINAL bash — 80x24
> Ready. Click "Run" to execute.
>